<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<div class="portlet box blue">
	<div class="portlet-title">
		<div class="caption">
			<i class="fa fa-gift"></i>当前仓库
		</div>
	</div>
	<div class="portlet-body form">
		<form id="warehouseForm" class="form-horizontal form-bordered"
			action="/warehouse/save" method="post">
			<div class="form-group">
				<label class="col-md-3 control-label">所属类型:</label>
				<div class="col-md-4">
					<select name="warehouseTypeId" id="select" class="form-control"
						onchange="gradeChange()">
						<c:forEach items="${warehouseType}" var="type" varStatus="status">
							<option value="${type.id}"
								<c:if test="${warehouse.warehouseTypeId == type.id}"> selected
							</c:if>>${type.name}</option>
						</c:forEach>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-md-3 control-label">仓库名称:</label>
				<div class="col-md-4">
					<input type="text" name="name" class="form-control"
						value="${warehouse.name}" maxlength="45" required />
				</div>
			</div>
			<div class="form-group">
				<label class="col-md-3 control-label">所在地区:</label>
				<div class="col-md-4">
					<div style="width: 33%; float: left;">
						<input type="text" name="country" placeholder="国家"
							class="form-control" value="${warehouse.country}" maxlength="45"
							required />
					</div>
					<div style="width: 33%; float: left;">
						<input type="text" name="state" placeholder="州(省)"
							class="form-control" value="${warehouse.state}" maxlength="45"
							required />
					</div>
					<div style="width: 33%; float: left;">
						<input type="text" name="city" placeholder="城市"
							class="form-control" value="${warehouse.city}" maxlength="45"
							required />
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-md-3 control-label">详细地址:</label>
				<div class="col-md-4">
					<input type="text" name="moreAddress" class="form-control"
						value="${warehouse.moreAddress}" maxlength="45" required />
				</div>
			</div>
			<div class="form-group">
				<label class="col-md-3 control-label">寄件人:</label>
				<div class="col-md-4">
					<input type="text" name="code" class="form-control"
						value="${warehouse.code}" maxlength="45" required />
				</div>
			</div>
			<div class="form-group">
				<label class="col-md-3 control-label">邮编:</label>
				<div class="col-md-4">
					<input type="text" name="zipcode" class="form-control"
						value="${warehouse.zipcode}" maxlength="45" required />
				</div>
			</div>
			<div class="form-group">
				<label class="col-md-3 control-label">联系电话:</label>
				<div class="col-md-4">
					<input type="text" name="phone" class="form-control"
						value="${warehouse.phone}" maxlength="45" required />
				</div>
			</div>
			<div class="form-actions">
				<div class="col-md-9 col-md-offset-3">
					<button type="button" class="btn btn-primary"
						onclick="saveWarehouse(this)">
						<spring:message code="btn.save"></spring:message>
					</button>
					<button type="reset" class="btn btn-default" onclick="cancels()">
						关闭</button>
				</div>
			</div>
			<input type="hidden" name="id" value="${warehouse.id}">
		</form>
	</div>
</div>
<script type="text/JavaScript">
	function gradeChange() {
		var objS = document.getElementById("select");
		var warehouseTypeId = objS.options[objS.selectedIndex].value;
	}
</script>
<script type="text/javascript"
	src="<c:url value="/static/custom/datepicker-util.js"></c:url>"></script>
<script type="text/javascript">
	$(function() {
	});

	/** 保存仓库 */
	function saveWarehouse(obj) {
		if ($(obj).closest('form').valid()) {
			$.when($.ajax({
				type : 'post',
				url : webRoot + $(obj).closest('form').attr('action'),
				data : $(obj).closest('form').serialize(),
				dataType : 'json'
			})).done(function(data) {
				alert(messages[data.result]);
				var id = data.warehouseId;
				if (data.result == "save_success") {
					$.ajax({
						type : 'post',
						url : webRoot + '/warehouse/init',
						dataType : 'html',
						success : function(data) {
							$(".panel-content").html(data);
							if (id != 0) {
								test123(id);
							}
						}
					})
				}
			}).fail(function(data) {
				alert("发生未知错误");
			})
		}
	}
</script>